package com.o2opay.car.service;

import com.github.pagehelper.page.PageMethod;
import com.o2opay.car.common.annotation.ServiceLog;
import com.o2opay.car.common.pojo.AjaxResult;
import com.o2opay.car.common.pojo.PageAjax;
import com.o2opay.car.common.utils.AppUtil;
import com.o2opay.car.mapper.EqpInfoMapper;
import com.o2opay.car.model.EqpInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by tugou on 2018/1/15.
 */
@Service
public class EqpInfoService extends AbstratService<EqpInfo> {
    @Autowired
    EqpInfoMapper eqpInfoMapper;

    @ServiceLog("查询终端信息列表")
    public PageAjax<EqpInfo> queryPage(PageAjax<EqpInfo> page, EqpInfo eqp){
        PageMethod.startPage(page.getPageNo(), page.getPageSize());
        List<EqpInfo> list = eqpInfoMapper.queryList(eqp);
        return AppUtil.returnPage(list);
    }

    @ServiceLog("添加终端")
    public AjaxResult saveEqp(EqpInfo eqp){
        String result = null;
        EqpInfo $eqpInfo = eqpInfoMapper.queryByEqpNum(eqp.getEqpNum());
        if(null == $eqpInfo){
            save(eqp);
        }
        else{
            result = "该编号的终端已经存在";
        }
        return AppUtil.returnObj(result);
    }
}
